<!DOCTYPE html>
<html class="iframe-h" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}"/>
		<link rel="stylesheet" type="text/css" th:href="@{/css/admin.css}"/>
		<link rel="stylesheet" type="text/css" th:href="@{/lib/bootstraps/css/bootstrap.css}"/>

	</head>

	<body>

		<div class="col-sm-2">
			<h2>部门</h2>
			<div id="treeview12" class=""></div>
		</div>

		<div class="col-sm-10">
			<div class="wrap-container clearfix">
				<div class="column-content-detail">
					<form class="layui-form" action="">
						<div class="layui-form-item">
							<div class="layui-inline tool-btn">
								<button class="layui-btn layui-btn-small layui-btn-normal addBtn" data-url="/user/toAdd"><i class="layui-icon">&#xe654;</i></button>
								<button class="layui-btn layui-btn-small layui-btn-danger delBtn"  data-url="/user/delete"><i class="layui-icon">&#xe640;</i></button>
								<button class="layui-btn layui-btn-small ayui-btn-normal assign"  data-url="/user/assignUser"><i class="layui-icon">&#xe770;</i></button>
								<button class="layui-btn layui-btn-small layui-btn-normal updateBtn"  data-url="/user/toUpdate"><i class="layui-icon">&#xe642;</i></button>
							</div>
							<!--<div class="layui-inline">
								<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
							</div>-->

							<!--<button class="layui-btn layui-btn-normal" lay-submit="search">搜索</button>-->
						</div>
					</form>
					<table class="layui-table" lay-data="{height: 'full', cellMinWidth: 80,  limit:15,limits:[15,30],
						url:'/user/list', page:true, id:'test'}" lay-filter="test" id="test">
						<thead>
						<tr>
							<th lay-data="{type:'checkbox'}">ID</th>
							<th lay-data="{field:'id',align:'center'}">id</th>
							<th lay-data="{field:'userNameCn',align:'center'}">姓名</th>
							<th lay-data="{field:'groupId', align:'center'}">部门ID</th>
							<th lay-data="{field:'groupName', align:'center'}">部门</th>
							<th lay-data="{field:'stationId', align:'center'}">岗位ID</th>
							<th lay-data="{field:'stationName', align:'center'}">岗位</th>
							<th lay-data="{field:'isLeader', align:'center',templet: '#isLeaderTem'}">部门领导</th>
							<th lay-data="{field:'status', align:'center',templet: '#checkboxTpl'}">状态</th>
						</tr>
						</thead>
					</table>

				</div>
			</div>

		</div>


		<script th:src="@{/js/jquery-3.2.1.min.js}" type="text/javascript" charset="utf-8"></script>
		<script th:src="@{/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
		<script th:src="@{/js/common.js}" type="text/javascript" charset="utf-8"></script>
		<script th:src="@{/lib/bootstraps/js/treeview/bootstrap-treeview.js}" type="text/javascript" charset="utf-8"></script>


		<script type="text/html" id="checkboxTpl">
			<input type="checkbox" name="lock" value="{{d.id}}" title="禁用" lay-filter="lockDemo" {{ d.status == 1?'checked':''}}>
		</script>

		<script type="text/html" id="isLeaderTem">
			{{#  if(d.isLeader== 0){ }}
			部门员工
			{{#  }else if(d.isLeader== 1){ }}
			部门领导
			{{#  }}}
		</script>
		<script>

			$(function () {
				$.ajax({
					url: '/dept/deptTree',
					type: 'get',
					dataType: 'json',
					success: function (data) {
						var $tree = $('#treeview12').treeview({
							data: data,
							levels: 1,
							color: "#428bca",
							expandIcon: 'glyphicon glyphicon-chevron-right',
							collapseIcon: 'glyphicon glyphicon-chevron-down',
							nodeIcon: 'glyphicon glyphicon-bookmark',
							onNodeSelected: function(event, node) {
								layui.table.reload('test', {
									page: {
										curr: 1 //重新从第 1 页开始
									}
									, where: {
										deptId: node.id
									}
								})
							},
						});
					}
				})
			});




			layui.use(['table','tree','jquery'], function() {
				var table = layui.table,
					form = layui.form,
                    $ = layui.jquery,
					tree = layui.tree;

                //获取当前iframe的name值
                var iframeObj = $(window.frameElement).attr('name');

				table.on('tool(test)', function(obj){
					var data = obj.data;


				});
                form.on('select(status)', function(data) {
                    var type = data.value;
                    table.reload('test', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            type: type
                        }
                    })
                });

                form.on('checkbox(lockDemo)', function(obj){
                    //do more thing
                    //layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
                    $.ajax({
                        url:'/user/changeStatus?id='+this.value+"&boolStatus="+new Boolean(obj.elem.checked),
                        type: 'post',
                        dataType:'json',
                        success:function (data){
                            if(data.code === 200){
                                layer.msg("修改成功");
                            }
                        }
                    });
                });



            });

		</script>
	</body>

</html>